import { getUserAccount, modifyName, modifyPassword} from '@/api/account'


const state = {
    account: {},//当前用户账号信息
}

const mutations = {
    SET_ACCOUNT_DATA:(state,new_account_data)=>{
        state.account = new_account_data
    },
    NULL:()=>{}
}

const actions = {
    //通过id获取用户信息
    getAccountInfo({ commit },userId){
        return new Promise((resolve, reject) => {
            getUserAccount(userId).then(response => {
                if (response) {
                    commit('SET_ACCOUNT_DATA',response.data.data)
                }
                resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
    },
    //修改基本信息
    modifyInfo({ commit },params){
        return new Promise((resolve, reject) => {
            modifyName(params).then(response => {
                resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
    },         
    //修改密码
    modifyPwd({ commit },params){
        return new Promise((resolve, reject) => {
            modifyPassword(params).then(response => {
                resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
    }  
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}